#include <DotSort/Tube.hpp>

#include <cstdint>

Tube::Tube(uint8_t size) : size(size), dotCount(0)
{
	this->array = new uint8_t[size]();
}

Tube::~Tube()
{
	delete[] this->array;
}

void Tube::push(uint8_t value)
{
	this->array[this->dotCount] = value;
	this->dotCount++;
}

void Tube::pop()
{
	this->array[this->dotCount - 1] = 0;
	this->dotCount--;
}

bool Tube::isEmpty() const
{
	return (this->dotCount == 0);
}

bool Tube::isFull() const
{
	return (this->dotCount == this->size);
}

bool Tube::isCompleted() const
{
	for(uint8_t i = 1; i < this->size; ++i)
	{
		if(this->array[i] != this->array[0])
		{
			return false;
		}
	}
	return true;
}

const uint8_t& Tube::top() const
{
	return this->array[this->dotCount - 1];
}

const uint8_t& Tube::operator[](uint8_t index) const
{
	return this->array[index];
}
